﻿/*========================== 
 * @author 郑金泉
 * @desc SQL IN 条件类
 * ========================= */
using System;
using System.Collections.Generic;
using System.Text;

using Obsidian.Edm;

namespace Obsidian.Data.Sql
{
    public class InCondition : SqlCondition, ISqlCondition
    {
        private ModelField _modelField;
        protected InClauseKeyWord _clauseKeyWord = InClauseKeyWord.IN;
        private string _inValue = null;

        public InCondition(ModelField field, string inValue)
        {
            this.Init(Sql.LogicalOperator.AND, field, InClauseKeyWord.IN, inValue);
        }

        public InCondition(LogicalOperator logicalOperator, ModelField field, string inValue)
        {
            this.Init(logicalOperator, field, InClauseKeyWord.IN, inValue);
        }

        public InCondition(ModelField field, InClauseKeyWord inClauseKeyWord, string inValue)
        {
            this.Init(Sql.LogicalOperator.AND, field, inClauseKeyWord, inValue);
        }

        public InCondition(LogicalOperator logicalOperator, ModelField field, InClauseKeyWord inClauseKeyWord, string inValue)
        {
            this.Init(logicalOperator, field, inClauseKeyWord, inValue);
        }

        private void Init(LogicalOperator logicalOperator, ModelField field, InClauseKeyWord clauseKeyWord, string inValue)
        {
            this.LogicalOperator = logicalOperator;
            this._modelField = field;
            this._clauseKeyWord = clauseKeyWord;
            this._inValue = inValue;
        }

        public string BuildSqlText()
        {
            if(this._clauseKeyWord == InClauseKeyWord.NOT_IN)
                return this._modelField.GetDbField().TablePrefixName + " NOT IN (" + this._inValue + ") ";
            else
                return this._modelField.GetDbField().TablePrefixName + " IN (" + this._inValue + ") ";
        }

    }

    public enum InClauseKeyWord
    {
        IN,
        NOT_IN
    }

}
